package com.cefa.edu.dao;

import com.cefa.edu.model.Course;
import com.cefa.edu.pojo.Class;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * 班级
 * @author huangzehui
 * @date 18-8-10 上午8:56
 */
@Mapper
public interface ClassMapper {


    @Results(id = "classMap", value = {
            @Result(property = "id", column = "id"),
            @Result(property = "className", column = "class_name"),
            @Result(property = "sort", column = "sort"),
            @Result(property = "schoolId", column = "school_id"),
            @Result(property = "count", column = "count"),
            @Result(property = "status", column = "status")
    })
    List<Class> findCourseListByLevelId(@Param("id") Integer id);
    @Update("update cefa_edu_class set state=1  WHERE id in (${ids})")
    void deleteClassByIds(@Param("ids") String ids);

    /**
     * @aa 根据班级id 获取对应的班级数据
     * @aa add by chaijian 2018-08-14
     * @return
     */
    @Results(id="classMapById",value = {
            @Result(property = "id",column = "id"),
            @Result(property = "className",column = "class_name"),
            @Result(property = "sort",column = "sort"),
            @Result(property = "schoolId",column = "school_id"),
            @Result(property = "count",column = "count"),
            @Result(property = "state",column = "state")
    })
    @Select({"select c.* from cefa_edu_class c where c.state=0 and c.id=#{id}"})
    Class getClassById(Integer id);

    /**
     * @aa 添加班级数据
     * @aa add by chaijian 2018-08-15
     */
    @Insert({"insert into cefa_edu_class(class_name,school_id)values(#{className},#{schoolId})"})
    @Options(useGeneratedKeys = true,keyProperty="id")
    int saveClass(Class classBean);

    @Update({"update cefa_edu_class set class_name = #{className} where id = #{classId}"})
    int updateClass(@Param("classId") Integer classId,@Param("className") String className);

    @Results(id="classMapById",value = {
            @Result(property = "id",column = "id"),
            @Result(property = "className",column = "class_name"),
            @Result(property = "sort",column = "sort"),
            @Result(property = "schoolId",column = "school_id"),
            @Result(property = "count",column = "count"),
            @Result(property = "state",column = "state")
    })
    @Select({"select id,class_name,sort,school_id,count,state from cefa_edu_class  where state=0 and id=#{id}"})
    @ResultMap(value="classMapById")
    Class getClassById2(@Param("id")Integer id);
}


